package cn.edu.scau.cmi.xiehaizhou.client;

import cn.edu.scau.cmi.xiehaizhou.simpleFactoryMethod.AutoInsurance;
import cn.edu.scau.cmi.xiehaizhou.simpleFactoryMethod.PolicyProducer;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SimpleFactoryMethodCilent extends Application{
	@Override
	public void start(Stage primaryStage)
	{
		primaryStage.setTitle("简单工厂模式");
		
		//分三部分布局
		VBox pane1 = new VBox();
		HBox pane2 = new HBox();
		GridPane pane3 = new GridPane();
		
		pane1.setAlignment(Pos.CENTER);
		pane2.setAlignment(Pos.CENTER);
		pane3.setAlignment(Pos.CENTER);
		pane3.setVgap(80);
		pane3.setHgap(30);
		
		//右上角部分
		pane3.setPadding(new Insets(10,10,10,10));
		pane3.add(new Label("姓名："), 0, 0);
		pane3.add(new Label("谢海洲"), 1, 0);
		pane3.add(new Label("学号："), 2, 0);
		pane3.add(new Label("201627010222"), 3, 0);
		pane3.add(new Label("请选择保险"), 0, 1);
		ComboBox<String> cbo = new ComboBox<String>();
		cbo.getItems().addAll("bodyInjure", "collision", "com", "personInjure", "property");
		pane3.add(cbo, 1, 1);
		Button btn = new Button("显示保险信息");
		pane3.add(btn, 1, 2);
		
		//照片部分
		Image image = new Image("file:E:\\Image\\Image1.jpg");
		ImageView imv = new ImageView(image);
		imv.setFitHeight(250);
		imv.setFitWidth(200);
		pane2.getChildren().addAll(imv, pane3);
		
		//文本域部分
		TextArea txt = new TextArea();
		txt.setEditable(false);
		pane1.getChildren().addAll(pane2, txt);
		
		//按钮事件
				btn.setOnAction(e ->
				{
					String type = cbo.getSelectionModel().getSelectedItem();
					AutoInsurance ai = PolicyProducer.getPolicyObj(type);
					String desc = ai.getInsurInfo();
					txt.setText(desc);
				}
						);
		
		Scene scene = new Scene(pane1, 700, 500);
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}
	
	public static void main(String[] args)
	{
		Application.launch(args);
	}
}
